const app = getApp()
import {
  parseTime
} from '../../utils/util.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hospitalId: '',
    isvisible: false,
    DeviceInfoCount:null,
    lifeSpanInfo:null
  },

  aisleHeld(e) {
    console.log(e.currentTarget.dataset.id);
    let datainfo = e.currentTarget.dataset.id
    let that = this
    if(datainfo==''){
      return
    }
    datainfo.lastUsedDate = parseTime(datainfo.lastUsedDate, '{y}年{m}月{d}日 {h}:{i}:{s}')
    datainfo.firstActivationDate = parseTime(datainfo.firstActivationDate, '{y}年{m}月{d}日 {h}:{i}:{s}')
    that.setData({
      isvisible: true,
      lifeSpanInfo:datainfo
    })
  },
  tapEvent() {
    let that = this
    that.setData({
      isvisible: false
    })
  },
  getList() {
    let that = this
    let data = {}
    data.hospitalId = that.data.hospitalId
    wx.request({
      url: app.globalData.serverUrlgdb + '/statistics/count/dev',
      method: 'POST',
      header: {
        'token': wx.getStorageSync('token')
      },
      data,
      success:res=>{
        let resp = res.data
        if(resp.code == 200){
          if(resp.data.DeviceInfoCount.devices.length>0){
            resp.data.DeviceInfoCount.devices.map(item=>{
              item.namexh = item.deviceNo.slice(0,1)==6?'GD-830':'GD-825'
              // if(item.thLifeSpans.length>0){
              //   item.thLifeSpans.map(v=>{
              //     if(v.channel=='三'){
              //       v.sortdiy = 2
              //     }else if(v.channel=='二'){
              //       v.sortdiy = 1
              //     }else{
              //       v.sortdiy = 0
              //     }
              //   })
              //   item.thLifeSpans.sort((a, b) => a.sortdiy - b.sortdiy)
              // }
            })
            
          }
          
          that.setData({
            DeviceInfoCount:resp.data.DeviceInfoCount
          })
          console.log(resp.data.DeviceInfoCount,'end');
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id);
    this.setData({
      hospitalId: options.id
    })
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getList()
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})